package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.*;
import com.mall.user.annotation.Anoymous;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author: hdf
 * @class: ShoppingByHdfController
 */

@Slf4j
@RestController
@RequestMapping("/shopping")
@Api("商城商品控制层")
public class ShoppingByHdfController {

    @Reference(interfaceClass = IProductService.class,timeout = 2000,retries = 0,check = false)
    IProductService iProductService;

    //Integer page,Integer size,Integer sort,Double priceGt,Double priceLte
    @Anoymous   //表示这个请求不需要登录认证
    @GetMapping("goods")
    public ResponseData shoppingGoods(AllProductRequest request){

        // request.setPage(page);
        // request.setSize(size);
        AllProductResponse response = iProductService.getAllProduct(request);

        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            AllProductDto allProductDto = new AllProductDto();
            allProductDto.setData(response.getProductDtoList());
            allProductDto.setTotal(response.getTotal());
            return new ResponseUtil().setData(allProductDto);
        } else if (ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode().equals((response.getCode()))){
            return new ResponseUtil().setErrorMsg(response.getMsg());
        }

        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


    @Anoymous //表示这个请求不需要登录认证
    @GetMapping("recommend")
    public ResponseData shoppingRecommend(){

        RecommendResponse response = iProductService.getRecommendGoods();
        RecommendByHdfDto recommendByHdfDto = new RecommendByHdfDto();
        recommendByHdfDto.setPanelDtos(response.getPanelContentItemDtos());

        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            return new ResponseUtil().setData(recommendByHdfDto.getPanelDtos());
        }

        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

}
